import {FormProps, FormSchema} from '/@/components/Table';

import {BasicColumn} from '/@/components/Table/src/types/table';
import {uploadApi} from '/@/api/sys/upload';
import {h} from "vue";
import {Tinymce} from "/@/components/Tinymce";
import {getJulyDictItemListByTypeApi} from "/@/api/admin/julyDictItemApi";
import {websiteExpertListApi} from "/@/api/website/websiteExpertApi";
import {Tag} from "ant-design-vue";


//表格显示列
export function getBasicColumns(): BasicColumn[] {
  // @ts-ignore
  return [
    {
      title: 'ID',
      dataIndex: 'activityId',
      fixed: 'left',
      width: 100,
    },
    {
      title: '活动名称',
      dataIndex: 'activityName',
      width: 150,

    },
    {
      title: '活动简介',
      dataIndex: 'activityBrief',
      width: 100,
    },
    {
      title: '开始时间',
      dataIndex: 'activityBeginTime',
      width: 100,
    },
    {
      title: '结束时间',
      dataIndex: 'activityEndTime',
      width: 100,
    },
    {
      title: '参加活动人数',
      dataIndex: 'functionAttendance',
      width: 100,
    },
    {
      title: '参加机构数量',
      dataIndex: 'mechanisms',
      width: 100,
    },
    {
      title: '报名电话',
      dataIndex: 'registrationTelephone',
      width: 100,
    },
    {
      title: '报名微信',
      dataIndex: 'registrationWechat',
      width: 100,
    },
    {
      title: '活动地址',
      dataIndex: 'activityAddress',
      width: 100,
    },
    {
      title: '是否预热',
      dataIndex: 'isPreheat',
      width: 100,
      customRender: ({record}) => {
        let isPreheat = record.isPreheat;
        let color=''
        switch (isPreheat) {
          case 0:
            isPreheat = '是';
            color = 'purple'
            break;
          case 1:
            isPreheat = '否';
            color = 'orange'
            break;
          default:
        }
        return h(Tag, {color: color}, () => isPreheat);
      },
    },
    {
      title: '排序',
      dataIndex: 'indexOrder',
      width: 100,
    },
  ];
}

export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 150,
    baseColProps: {lg: 6, md: 24},
    schemas: formParamSchema,
  };
}


//编辑表单
export const formParamSchema: FormSchema[] = [
  {
    field: 'activityName',
    label: '活动名称',
    component: 'Input',
  },
  {
    field: '[activityBeginTime, activityEndTime]',
    label: '活动时间范围',
    component: 'RangePicker',
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      placeholder: ['开始时间', '结束时间'],
      showTime: { format: 'HH:mm:ss' },
    },
  },
];

//编辑表单
export const formSchema: FormSchema[] = [
  {
    field: 'divider-basic',
    component: 'Divider',
    label: '基础信息',
    colProps: {
      span: 24,
    },
  },
  {
    field: 'activityName',
    label: '活动名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'activityBrief',
    label: '活动简介',
    component: 'InputTextArea',
    required: true,
  },
  {
    field: 'activityTime',
    label: '活动时间范围',
    component: 'RangePicker',
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      placeholder: ['开始时间', '结束时间'],
      showTime: { format: 'HH:mm:ss' },
    },
  },
  {
    field: 'functionAttendance',
    label: '参加活动人数',
    component: 'InputNumber',
    required: true,
  },
  {
    field: 'mechanisms',
    label: '参加机构数量',
    component: 'InputNumber',
    required: true,
  },
  {
    field: 'experts',
    label: '评委数量',
    component: 'InputNumber',
  },
  {
    field: 'indexOrder',
    label: '排序',
    component: 'InputNumber',
    required: true,
  },
  {
    field: 'registrationTelephone',
    label: '报名电话',
    component: 'Input',
    required: true,
  },
  {
    field: 'registrationWechat',
    label: '报名微信',
    component: 'Input',
    required: true,
  },
  {
    field: 'activityAddress',
    label: '活动地址',
    component: 'Input',
    required: true,
  },
  {
    field: 'coverImage',
    label: '封面图',
    component: 'Upload',
    componentProps: {
      api: uploadApi,
      accept: ['jpg', 'png', 'jpeg'],
      maxNumber: 1,
      maxSize: 1,
      helpText: '请上传png/jpg 等图片文件，文件大小小于1M,宽高比为7:4',
    },
  },
  {
    field: 'isPreheat',
    label: '是否预热',
    component: 'RadioButtonGroup',
    defaultValue: '',
    componentProps: {
      options: [
        { label: '全部', value: '' },
        { label: '是', value: 0 },
        { label: '否', value: 1 },
      ],
    },
  },
  {
    field: 'advanceNoticeImage',
    label: '活动预告图',
    component: 'Upload',
    componentProps: {
      api: uploadApi,
      accept: ['jpg', 'png', 'jpeg'],
      maxNumber: 1,
      maxSize: 1,
      helpText: '请上传png/jpg 等图片文件，文件大小小于1M,宽高比为7:4',
    },
  },
  {
    field: 'activityDesc',
    component: 'Input',
    label: '活动详情',
    defaultValue: '',
    rules: [{required: true}],
    render: ({model, field}) => {
      return h(Tinymce, {
        value: model[field],
        onChange: (value: string) => {
          model[field] = value;
        },
      });
    },
  },
  {
    field: 'divider-cad-basic',
    component: 'Divider',
    label: '活动日程信息',
    colProps: {
      span: 24,
    },
  },
  {
    field: 'scheduleName0',
    component: 'Input',
    label: '日程名称',
    colProps: {
      lg: 12, md: 12
    },
  },

  {
    field: 'scheduleBeginTime0',
    component: 'TimePicker',
    label: '开始时间',
    colProps: {
      lg: 6, md: 6
    },
  },
  {
    field: 'scheduleEndTime0',
    component: 'TimePicker',
    label: '结束时间',
    colProps: {
      lg: 6, md: 6
    },
  },
  {
    field: 'scheduleBrief0',
    component: 'InputTextArea',
    label: '日程简介',
    colProps: {
      lg: 18, md: 18
    },
  },
  {
    field: 'indexOrder0',
    component: 'InputNumber',
    label: '日程排序',
    colProps: {
      lg: 4, md: 4
    },
  },
  {
    field: '0',
    component: 'Input',
    label: ' ',
    colProps: {
      lg: 2, md: 2
    },
    slot: 'add',
  },
];


export const formExpertSchema: FormSchema[] = [
  {
    field: 'divider-cad-basic',
    component: 'Divider',
    label: '活动嘉宾/评委信息',
    colProps: {
      span: 24,
    },
  },
  {
    field: 'expertId0',
    label: '专家/嘉宾',
    component: 'ApiSelect',
    componentProps: {
      api: websiteExpertListApi,
      labelField: 'expertName',
      valueField: 'expertId',
    },
    colProps: {
      lg: 10, md: 10
    },
  },
  {
    field: 'indexOrder0',
    component: 'InputNumber',
    label: '排序',
    colProps: {
      lg: 10, md: 10
    },
  },
  {
    field: '0',
    component: 'Input',
    label: ' ',
    colProps: {
      lg: 4, md: 4
    },
    slot: 'add',
  },
];
